package gui.CustomerServiceWorker;

import gui.Login.MessageCenter;
import gui.client.ClientGUI;

import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

import control.LoginController;

import system.SystemTypes;
import system.VCP;
/**
 * this class use  as the main menu for Customer Service Screen 
 * @author G8
 *
 */
public class CustomerServiceGUI extends JPanel implements ActionListener{
	private JButton btnExit;
	private JButton btnResolution;
	private JButton btnSaveParking;
	private ResolutionCenterScreen resolutionCenterScreen;
	private CustomerSaveParkingScreen customerSaveParkingScreen;
	private MessageCenter messageCenter;
	private JLabel lblDateTime;
	private JButton btnMessage;
	private JButton btnClientMenu;
	private ClientGUI clientGUI;

	/**
	 *Customer Service Screen  Constructor 
	 */
	public CustomerServiceGUI() {
		super();
		initialize();
	}
	/**
	 * This method contains the view of the Panel
	 */
	private void initialize() {
		setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Customer Service Worker Menu", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		setBackground(SystemColor.menu);
		setBounds(VCP.guiX,VCP.guiY,500,400);
		setLayout(null);
		VCP.frame.setBounds(this.getBounds());
		
		btnExit = new JButton("Logout");
		btnExit.setSize(150, 30);
		btnExit.setBounds(393, 22, 78, 35);
		btnExit.addActionListener(this);
		add(btnExit);
		
		//Add buttons:
		
		btnResolution = new JButton("Resolution Center");
		btnResolution.setBounds(20, 53, 207, 46);
		btnResolution.addActionListener(this);
		add(btnResolution);
		
		btnSaveParking = new JButton("Save Parking");
		btnSaveParking.setBounds(20, 110, 207, 46);
		btnSaveParking.addActionListener(this);
		add(btnSaveParking);
		
		btnMessage = new JButton("Message Center");
		btnMessage.setBounds(264, 110, 207, 46);
		btnMessage.addActionListener(this);
		add(btnMessage);
		
		lblDateTime = new JLabel("Date and Time");
		lblDateTime.setBounds(201, 332, 97, 14);
		lblDateTime.setText(VCP.getDateTime());
		add(lblDateTime);
		
		btnClientMenu = new JButton("Client Menu");
		btnClientMenu.setBounds(264, 167, 207, 46);
		btnClientMenu.addActionListener(this);
		add(btnClientMenu);
	}
	/**
	 * This method listens to the buttons on the panel
	 * @param e is the buttons the user Click
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnClientMenu){
			clientGUI = new ClientGUI();
			VCP.setScreen(this, clientGUI);
		}
		if (e.getSource() == btnMessage){
			try{
				messageCenter = new MessageCenter();
				VCP.setScreen(this, messageCenter);
			}
			catch(Exception ae){
				JOptionPane.showMessageDialog(null, "No new messages !", "Attention",
	                    JOptionPane.INFORMATION_MESSAGE);
			}
		}
		if (e.getSource() == btnResolution){
			resolutionCenterScreen = new ResolutionCenterScreen();
			VCP.setScreen(this, resolutionCenterScreen);
		}
		if (e.getSource() == btnSaveParking){
			customerSaveParkingScreen = new CustomerSaveParkingScreen();
			VCP.setScreen(this, customerSaveParkingScreen);
		}
		if (e.getSource() == btnExit){
			SystemTypes userToLogout = new SystemTypes(VCP.currentUser,null);
			boolean logoutRes = LoginController.LogOut(userToLogout);
			if (logoutRes)
				VCP.setGUI(0, this);
			else{
				JOptionPane.showMessageDialog(null, "Failed to logout!", "Error",
	                    JOptionPane.ERROR_MESSAGE);
			}
		}	
	}
}
